package acwing._2LanQiao.test;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._2LanQiao.test
 * @File : binaryIndexedTree.java
 * @Author : WangRuoyu
 * @Date : 2023/4/7 17:03
 */

import java.io.*;

public class binaryIndexedTree {

    static int lowbit(int x) {
        return x & -x;
    }

    static void insert(int x, int c, int n, int[] bTree) {
        for (int i = x; i <= n; i += lowbit(i)) {
            bTree[i] += c;
        }
    }

    static int sum(int x, int n, int[] bTree) {
        int res = 0;
        for (int i = x; i >= 1; i -= lowbit(i)) {
            res += bTree[i];
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = 17;
        int[] a = new int[n + 1];
        int[] bTree = new int[n + 1];
        int[] s = new int[n + 1];
        for (int i = 1; i <= n; ++i) {
            a[i] = i;
            s[i] = s[i - 1] + a[i];
            insert(i, i, n, bTree);
        }

        for (int i = 1; i <= n; ++i) {
            System.out.print(a[i]+" ");
        }
        System.out.println();
        for (int i = 1; i <= n; ++i) {
            System.out.print(s[i]+" ");
        }
        System.out.println();
        for (int i = 1; i <= n; ++i) {
            System.out.print(sum(i, n, bTree)+" ");
        }
    }
}

